﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TaoBaoApi_TB_DownTrade : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            new TBCommon().BindTBShop(ddlShop);
    }   
    
    /// <summary>
    /// 下载淘宝订单
    /// </summary>
    protected void btnDown_Click(object sender, EventArgs e)
    {
        string name = ddlShop.SelectedItem.Text;
        if (name.Length == 0)
        {
            ShowMessage("请选择淘宝店铺。");
            return;
        }
        string password = ddlShop.SelectedValue;        
        //登录淘宝，获取sessionid
        string errMsg = null;       
        string sessionId = null;
        int ret = 0;
        string appkey=new TaoBaoAPI().GetAppKey();
        string certcode=new TaoBaoAPI().GetCertCode();
        ret = new TaoBaoAPI().GetTBSessionId(Page, name, password, appkey, ref errMsg, ref sessionId);
        if (ret != 0)
        {
            ShowMessage(errMsg);
            return;
        }
        //下载订单列表，及详细信息
        ret = new TB_Trade().DownTBTrade(name, password, appkey, certcode, sessionId);
        Response.Redirect("tb_trades.aspx");
    } 
    
    /// <summary>
    /// 显示提示信息
    /// </summary>
    void ShowMessage(string msg)
    {
        new TBCommon().ShowMessage(Page, msg);
    }    
}
